package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/index"
	"entgo.io/ent/schema/mixin"
)

type ApiExtend struct{}

// SysApi holds the schema definition for the SysApi entity.
type SysApi struct {
	ent.Schema
}

// Fields of the SysApi.
func (SysApi) Fields() []ent.Field {
	return []ent.Field{
		field.String("path").Comment("api路径"),
		field.String("description").Comment("api中文描述"),
		field.String("api_group").Comment("api 组"),
		field.String("method").Default("POST").Comment("http 请求方式"),
		field.Bool("default").Default(false).Comment("默认状态"),
		field.Time("delete_time").Optional().Comment("删除时间"),
		field.JSON("extent", ApiExtend{}).Optional().Comment("扩展信息"),
	}
}
func (SysApi) Mixin() []ent.Mixin {
	return []ent.Mixin{
		mixin.Time{},
	}
}

func (SysApi) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{Table: "sys_api"},
	}
}

func (SysApi) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("delete_time"),
		index.Fields("path", "method").Unique(),
	}
}

// Edges of the SysApi.
func (SysApi) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("roles", SysRole.Type).
			Ref("apis"),
	}
}
